package com.durian.base.rxhttp.param

import com.durian.base.rxhttp.cache.CacheStrategy
import okhttp3.Headers
import okhttp3.Request
import okhttp3.RequestBody
import java.io.File

/**
 * 说明：RxHttpParam
 * <p/>
 * 作者：Fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2020/04/24 18:05
 * <p/>
 * 版本：version 1.0
 */

interface IJsonParam<P> {
    fun setJsonParams(enable: Boolean = true, data: String? = null): P
}

interface IFileParam<P> {
    fun addFile(key: String, filePath: String, body: RequestBody? = null): P
    fun addFile(key: String, file: File, body: RequestBody? = null): P
}

interface IParam<P> {
    /**
     * @return 请求体
     * GET,HEAD不能有请求体
     * POST,PUT,PATCH请求必须有请求体
     */
    fun getRequestBody(): RequestBody?

    /**
     * @return 构建请求
     */
    fun buildRequest(): Request

    /**
     * 仅网络
     * @return 构建缓存策略
     */
    fun onlyNetwork(): P

    /**
     * 仅缓存
     * @param cacheValidTimeMillis 过期时间，单位秒，默认永久
     * @return 构建缓存策略
     */
    fun onlyCache(cacheValidTimeMillis: Int = -1): P

    /**
     * 读取网络失败后读取缓存
     * @param cacheValidTimeMillis 过期时间，单位秒，默认永久
     * @return 构建缓存策略
     */
    fun useCache(cacheValidTimeMillis: Int = -1): P

    /**
     * 设置缓存key
     */
    fun cacheKey(key:String): P

    /**
     * 设置缓存key
     */
    fun excludeCacheKey(vararg keys:String): P

    /**
     * 构建缓存策略
     */
    fun buildCacheStrategy(): CacheStrategy

    /**
     * 是否开启功能参数
     */
    fun setAssemblyEnable(enable: Boolean): P

    //    Headers
    fun getHeaders(): Headers
    fun getHeader(key: String): String?
    fun addHeader(key: String, value: String): P
    fun addHeader(line: String): P
    fun addHeader(map: Map<String, String>): P
    fun setHeader(key: String, value: String): P
    fun removeHeader(key: String): P

    //    Params
    fun addParam(key: String, value: Any, isEncoded: Boolean = false): P
    fun addParam(map: Map<String, Any>): P
    fun removeParam(key: String): P

    fun tag(key: String): P
}